<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('输送口管理')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "system/wareConveyor";

    $(function () {
        var options = {
            url: prefix + "/findList",
            modalName: "输送口管理",
            columns: [
                {
                    field: 'id',
                    title: 'ID',
                    align: 'center'
                },
                {
                    field: 'ssjNumber',
                    title: '编码',
                    align: 'center'
                },
                {
                    field: 'name',
                    title: '名称',
                    align: 'center'
                },
                {
                    field: 'state',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, row, index){
                        if(value == 0){
                            return "禁用";
                        }else if(value == 1){
                            return "启用";
                        }
                    }
                },
                {
                    field: 'type',
                    title: '类型',
                    align: 'center',
                    formatter: function(value, row, index){
                        if(value == 1){
                            return "入口";
                        }else if(value == 2){
                            return "出口";
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index){
                        var actions = [];
                        if(row.state == 0){
                            actions.push("<a class='btn btn-success btn-xs' href='javascript:void(0)' onclick=change(" + row.id + ',' + "'" + row.state + "'" + ")><i class='fa fa-key'></i>启用</a> ");
                        }else if(row.state == 1){
                            actions.push("<a class='btn btn-danger btn-xs' href='javascript:void(0)' onclick=change(" + row.id + ',' + "'" + row.state + "'" + ")><i class='fa fa-remove'></i>禁用</a> ");
                        }
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function change(id, state){
        layer.alert("确定进行此操作吗？", {
            title: "系统提示",
            btn: ['确定','取消'],
            yes: function(index, layero){
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: '/system/wareConveyor/startOrEnd',
                    data: {
                        id: id,
                        state: state
                    },
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        layer.close(index);
                        location.reload();
                    }
                })
            }
        });
    }
</script>
</body>
</html>
